package com.idanchuang.support.mybatis.crypt.config;

import com.idanchuang.component.core.config.AbstractCryptConfigBean;
import com.idanchuang.component.core.enums.AesEnum;

import java.util.Optional;

public class CryptConfigBean extends AbstractCryptConfigBean {

    public static CryptConfigBean INSTANCE;

    /**
     * 开启加解密功能
     */
    private boolean enable = true;
    /**
     * 开启加密
     */
    private boolean enableEncrypt = true;
    /**
     * 开启解密
     */
    private boolean enableDecrypt = true;

    {
        synchronized (CryptConfigBean.class) {
            if (CryptConfigBean.INSTANCE == null) {
                CryptConfigBean.INSTANCE = this;
            }
        }
    }

    public CryptConfigBean() {
        super(AesEnum.AES192, "lfjvncurhdlsmthgvkcjdyro", "crypt#");
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public boolean isEnableEncrypt() {
        return enableEncrypt;
    }

    public void setEnableEncrypt(boolean enableEncrypt) {
        this.enableEncrypt = enableEncrypt;
    }

    public boolean isEnableDecrypt() {
        return enableDecrypt;
    }

    public void setEnableDecrypt(boolean enableDecrypt) {
        this.enableDecrypt = enableDecrypt;
    }

    public static Optional<CryptConfigBean> getInstance() {
        return Optional.ofNullable(INSTANCE);
    }

    @Override
    public String toString() {
        return "CryptConfigBean{" +
                ", enable=" + enable +
                ", enableEncrypt=" + enableEncrypt +
                ", enableDecrypt=" + enableDecrypt +
                '}';
    }
}
